package tmproject.hlhj.fhp.cartrans.adapter

import android.graphics.Color
import android.widget.CheckBox
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import tmproject.hlhj.fhp.cartrans.R
import tmproject.hlhj.fhp.cartrans.activitys.ExamDetailAty
import tmproject.hlhj.fhp.cartrans.log

class ExamChooseAdp(private val datas:ArrayList<String>
                    ,private val checkHash:HashMap<Int,Boolean>,
                    private var isShowResult:Int,
                    private var rightAnwser:ArrayList<String>)
    :BaseQuickAdapter<String,BaseViewHolder>(R.layout.test_choose_item,datas) {
    override fun convert(helper: BaseViewHolder?, item: String?) {
        val box = helper?.getView<CheckBox>(R.id.cb)
        val text = helper?.getView<TextView>(R.id.itemContent)
        box?.isChecked = checkHash[helper?.adapterPosition]!!
        if (checkHash[helper?.adapterPosition]!!){
            text?.setTextColor(Color.parseColor("#de1414"))
        }else{
            text?.setTextColor(Color.parseColor("#333333"))
        }
        log("fhp","值没有改变？${isShowResult}")
        if (ExamDetailAty.isShowResult==1){
            val textView = helper?.getView<TextView>(R.id.itemTv)
            var isRight=false
            log("fhp","看看正确答案数组的值${rightAnwser.toString()}")
            for (i in 0..rightAnwser.size-1){
                if (rightAnwser[i].equals(helper?.adapterPosition.toString())){
                    isRight=true
                }
            }
            if (isRight){
                textView?.setBackgroundResource(R.mipmap.ic_correct)
                textView?.text = ""
            }else{
                textView?.setBackgroundResource(R.mipmap.ic_xx)
                when(helper?.adapterPosition){
                    0->{
                        helper?.setText(R.id.itemTv,"A")
                    }
                    1->{
                        helper?.setText(R.id.itemTv,"B")
                    }
                    2->{
                        helper?.setText(R.id.itemTv,"C")
                    }
                    3->{
                        helper?.setText(R.id.itemTv,"D")
                    }
                }
            }
            if (checkHash[helper?.adapterPosition]!!){
                val textView = helper?.getView<TextView>(R.id.itemTv)
                if (rightAnwser.contains(helper?.adapterPosition.toString())){

                }else{
                    textView?.setBackgroundResource(R.mipmap.ic_error)
                    textView?.text = ""
                }
            }else{

            }
        }else{
            val textView = helper?.getView<TextView>(R.id.itemTv)
            textView?.setBackgroundResource(R.mipmap.ic_xx)
            when(helper?.adapterPosition){
                0->{
                    helper?.setText(R.id.itemTv,"A")
                }
                1->{
                    helper?.setText(R.id.itemTv,"B")
                }
                2->{
                    helper?.setText(R.id.itemTv,"C")

                }
                3->{
                    helper?.setText(R.id.itemTv,"D")
                }
            }
        }


        helper?.setText(R.id.itemContent,item)
    }
}